﻿Imports Training.Common

Partial Public Class DeleteGroupUser
    Inherits System.Web.UI.Page
    Public uName As String ' user name
    Dim uid As Integer

    ''' <summary>
    ''' Page Load event, check for querystring data and assign to variables
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' check for querystring data
        If IsNothing(Request.QueryString("uid")) Or IsNothing(Request.QueryString("unm")) Then
            Response.Redirect("Users.aspx")
        Else
            uid = Request.QueryString("uid")
            uName = Request.QueryString("unm")
        End If
    End Sub

    ''' <summary>
    ''' Cancel button click event. User is not deleted
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>redirect back to Manage Users</remarks>
    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Response.Redirect("Users.aspx")
    End Sub

    ''' <summary>
    ''' Delete button click event. Delete all user data
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>redirect to Groups.aspx after completion</remarks>
    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        ' delete quiz and module data
        DeleteUserQuizModuleData(uid)

        ' delete login information
        Dim lname As String
        lname = GetUserLogin(uid)
        Membership.DeleteUser(lname)

        ' delete user record
        DeleteUserByID(uid)

        ' redirect
        Response.Redirect("Users.aspx")
    End Sub
End Class